package org.hot100_3;

import java.util.ArrayList;
import java.util.List;

public class leetcode114 {
    public void flatten(TreeNode root) {
        List<TreeNode> list = new ArrayList<>();
        treeToList(root, list);

        TreeNode treeNode = root;
        for (int i = 1; i < list.size(); i++) {
            treeNode.left = null;
            treeNode.right = list.get(i);
            treeNode = treeNode.right;
        }

    }

    private void treeToList(TreeNode root, List<TreeNode> list) {

        if (root == null) {
            return;
        }

        list.add(root);

        treeToList(root.left, list);

        treeToList(root.right, list);
    }
}
